/**
 * Game
 * Manage game mecanics and managers
 **/
var Game = function() {
	// Game objects
	this.mLevel = null;
	this.mEnemy = null;
	this.mPlayer = null;
	this.hud = null;
	this.mSpell = null;

	// Game state 
	this.waiting = null;
	this.stop = null;
	this.cleared = null;

	this.imgData = null;

	this.init = function() {
		log('*** INIT GAME ***');
		this.mSpell = new SpellManager();
		this.mSpell.init();
		this.mLevel = new LevelManager();
		this.mLevel.init();
		this.mScore = new ScoreManager();
		this.mScore.init();

		// Sprites loaded !
		IM.loadAll(function() {
			isLoadedImages = true;
		});
	}

	this.start = function() {
		log('*** START GAME ***');
		// Enemies
		this.mEnemy = new EnemyManager();
		this.mEnemy.init();
		// Players
		this.mPlayer = new PlayerManager();
		this.mPlayer.init();
		// HUD
		this.hud = new Hud();
		this.hud.init();

		// Restart Score
		this.mScore.restart();

		this.stop = false;
		this.waiting = false;
	}

	this.clear = function() {
		this.mLevel.destroy();
		this.mEnemy.destroy();
		this.mPlayer.destroy();

		this.stop = true;
		this.cleared = false;
	}

	this.update = function() {
		this.mLevel.update();
		this.mPlayer.update();
		this.hud.update();
		this.mEnemy.update();
		this.mSpell.update();
		this.render();
	}

	this.render = function() {
		this.mLevel.render();
		this.hud.render();
		this.mEnemy.render();
		this.mSpell.render();
		this.mPlayer.render();
	}

	this.currentPlayer = function() {
		return this.mPlayer.entities[0];
	}

};
